package vaadin.lab1;

import java.util.ArrayList;
import java.util.List;

import vaadin.lab1.ApplicationChrome.NavigationEvent;

import com.vaadin.Application;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.themes.Reindeer;

@SuppressWarnings("serial")
public class LabB extends Application implements
        ApplicationChrome.NavigationListener {
    private List<Object> viewIds = new ArrayList<Object>();
    private ApplicationChrome chrome;

    @Override
    public void init() {

        viewIds.add("View 1");
        viewIds.add("View 2");
        viewIds.add("View 3");

        chrome = new ApplicationChrome(viewIds);
        chrome.addListener(this);
        chrome.setSizeFull();
        Window mainWindow = new Window("Lab", chrome);
        setMainWindow(mainWindow);

        chrome.setCurrentView(createView(viewIds.get(0)));
    }

    private Component createView(Object viewId) {
        final Label lbl = new Label(viewId.toString());
        lbl.setSizeUndefined();
        lbl.setStyleName(Reindeer.LABEL_H1);
        VerticalLayout layout = new VerticalLayout();
        layout.setStyleName(Reindeer.LAYOUT_BLACK);
        layout.addComponent(lbl);
        layout.setComponentAlignment(lbl, Alignment.MIDDLE_CENTER);
        return layout;
    }

    @Override
    public void navigation(NavigationEvent event) {
        chrome.setCurrentView(createView(event.getViewId()));
    }
}